Refactoring, enabled and fixed some warnings