almost finished, fixed bugs