Fixed code bugs