Refactoring to be cleaner, more modular and removed some boilerplate+comments