Sure this code does not look nice, it is highly optimized for performance. Might clean that up later.