Refactoring and fix so new one hopefully works