Refactoring and I think I fixed the problem