Somewhat working logic for