Added exception for missing category and removed trailing whitespace
Added test (with mock) and removed some whitespace