Working category selection

The code is getting messy though... will tidy up soon.