made major changes to functions and methods