add permission checking
bug fixing