Commented code to make it easier to understand with new structure