Added cahing.
Added checking for invalid parameters.
Replaced "and" with "&&" and "or" with "||".
Merge pull request #1 from kaspernj/kj/caching_and_invalid_params

Added cahing and checking for invalid parameters