Fixed issue when serializing arrays and cleaned up code a bit