finally semi working version