Finished implementation of loops