moved some stuff around to be formatted better - credit to port for the idea