Refactoring, fixing compile issues
working