refactored home function