function for rearrange refactoring done to work with exercises and details