fixed bugs so runs in terminal