almost finalized code trimming