Code with improvements and bug fixes