Fixed code, needs debug finished