Fix date deserialization and refact code