[refactoring] Rewrote redundant code