Refactored whole sync process, merges and some minor changes

This contains the last changes I've made during the hackathon.