Code cleanup and refactored for a better overview when looking at it directly on Github