improve code to allow it to be run from other dirs