refactored the go function.