Moved output function to top, edited normalize function, tested!