fixed some consinstency checks and unitTest