Code refactoring, improve comment clarity and seperation of code
shorten methods to avoid too much nesting