complete new code and ready for prodiction 1.0