Fixed some bugs, added some permissions checks and overall preparatons for test.