Added session cache. Refactor logic. Add verification of primary key to be serializable.