Clean up, added some code to make the parameters easer to read and less likely to get out of control later.
Should still hold the same logic as before