3rd revision:revised and debugged