Removed unecessary tests and modified trim() to throw on invalid types