Code tested and fixed some minor bugs