Rewrite deriving(Decodable, Encodable)

Now it uses the generic deriving code and should in theory work in all cases.