Small refactoring, Fixed some issues