refactor and hotfixes