Adding some trimming and fixes