Added some asserts and made some simall changes