refactor for better code