fixed some part of code, reducing some logical redundancies