code refactoring to save space