Re-factoring functions, clean-ups