simplified, fixed bugs