20140516 2323 adjusted

adjusted some bug
modulized
delete unuseful variables