Added locking mechanism to prevent double openning(issue #3).