fixed errors, changed execution flow