fix access restriction
fixed some bugs and added tests