refactor and fixed some things