changed formatting, added comments and some pieces of code