moved logic to where it belongs