Separated sorting into different functions.
Merge branch 'Singleton' into dev