refactoring curtain code a bit