Changes as requested by Volodya, added locking tables