Use withMVar instead of bracket
Fixed warnings