better code refactor