Code-refactors + better error handling