general code refactor