working version. before conversion to package