Fixed bugs, improved the code, not completely debugged