Cleaned up trimOutput()