added copyright notices, clear code, added test