Re-factoring scattered codes

Clean-up
Cleanup-2
Cleanup-3
Cleanup-4
Cleanup-5
Cleanup-6