better error handling, remove newlines