Fixed some logic issues and updated documentation