cleaned up loops and conditionals