Re-factored code, more refactoring needed!