Refactor the CardLibrary and fix some minor things