logic move and cleanup