clear code and some design fixes