Added cap check when writing