Adding tests and fixing issues with loops.