Fixed a bug were i was counting wrong. Some other code improvements.