Added the trim function + fixes