cleaned all code and added upgrade path