Final version with some corrections and code organizations.