Moved trimming to only  where it's needed