Hopefull fixed the invalid key exception, not sure about the null pointer