Debugged working version