refactoring, performance improvements and adding some gui changes