code update to check some logic flaws