tidying/shortening up some code, fixing small bug