fixed mapping range of latch
improving test function
merge