moving bmp.unlock to its correct scope