Refactored part of the code, added routines and minimal galaxys2 support