Updated for optimal debugging and working version for internet