Reworked and condensed code

Revised to clean and reduce code