refactor and fix stuff