moved some functionality into each functions