organised the code a little