cleaned up code, cited sources