improved api to make it more usable when using in other scripts