a lot of logic reworked