added licence, couple of bug fixes