-fixed left boundary problem
-tidied up the if else's