organized the code a bit