fixed bugs in main(). more properly tested