cleaned up code a bit, more loops etc