fix bugs, clearer code