trim and cleanup