Additional code documentation and bug fixes