finished implementing trimmning. needs testing