Fix the implementation of expandCredits and add more tests