Refactoring from Andhieka