Add comments and bug fixes