created decode function and wrote tests for it