trying to implement in lisp... lots of ugly conditionals :(