Fixed a lot of errors. Some improvements in design.