working version. needs to be cleaned...