apply discussed changes
some cleanup, fix tests