final working version, feel free to play with it to tighten it