redid functionality to be cleaner