refactoring & optimizing