Implemented semantic verification

and bugfixes