Cleaner, stronger code.

3 procedures re-written in one. More robust and logic.