Added randomize / sort function

Cleaned up code