Fix bugs and refactor