Code formatted by human :P