Refactoring and optimize for Glass