Refoactor and Tests