refactored code. Input, output tests now pass. Was previously using an incorrect method to cast input