create CardManager class and clean up the code