updating code with bug fixes