removed unused code
Fixed count
Better exception handling