Some bug fixes and additional amendments

Minor changes made during testing and bug fixing of the code.