Working on refactoring this out but leaving as is for now.