modified so that it can work with tests. Added trimming