This should fixes an 500 error code, that showed up on some pages. Also added a test method to test this function.