Refactored a lot. Fixed some compilation issues