complete new code, ready for prodiction 1.0