Modified it a bit, hoping this will work better