Full working version
Cleanup code