cleaned up code, now uses functional style. yay reduce and inline array building!