Restructured code a bit for further implementation of categorizing/sorting functions