fixed out of bounds bug
fixed bug and slight tidy up