timob-12176: fix bugs + add some invalid input handling