minor cleanup things, got rid of another loop and use a condition instead