Functionality completed. Refactor to improve perfomance
and maintainabiliy