Added cahing and checking for invalid parameters