Refactoring slot code