Fixed some bugs, simplified some code, fixed constant in README