Implement trim

Implemented trim and a test for it.