Minor bugfixes + reformatted boilerplate code to be more readable