some improvements and bug fixes
correctly parses input data