Tidying up code and removing closing PHP tag