merge working code into master branch

this is probably a little more acceptable but I would have the else if on the same line as the closing bracket and place the comments on the first line of the block