Refactored the code, removed unnecessary if/else statements

Signed-off-by: Christoffer Johnsson <stoffe1992@hotmail.com>