(probably) completed idfs version (got a correct solution anyway)