Code clean up and licensed under CC BY SA 3.0