final working tested code on ASF