Card 772 Refactor code and add more specs