Sorry the code is a bit messy; not sure why it isn't working