Fix bugs and trim