cleane up the code a bit, also hid a surprise :D
added better annotations and comments, changed some names to make it more intuitive