Final working version
Deleted test code