Refactored code for readability. Unfortunately no speed improvements so
far.