Cleaned up code for ls.cpp