Some refactoring, minor fixes
Removed some warnings and unused code