updated readme. code refactoring. fixed a bug. added checks