Cleaned up output code with tests