Minified the code (ifs) and fixed bug in update operation.