REFACTOR: Removed duplicate code + lots of cleanups