removed redundant conditionals, optimized array to dict, refactorization