Fixed minor code bugs