Merged code from Cronus and fixed some issues