Update system.cpp

Cleaned up whitespace, removed redundant code and added edge cases for string cleanup