tidyed up code a bit...