somewhat complete version (not working yet)