Got rid of some unnesessary structure and loops.