Fixed merge conflicts, refactored some stuff