Main logic now works