optimized checking for index out of bounds
added custom serialization read/write