fixed bugs and added simulation