slight restructure of code and comments