Core pr 6

New permission and some logic rewrite based on review from PR5.