Add locking

Hi there! this branch adds locking as mentioned on #17