implement decode function