fixed coding guidelines and added more logic to cover all posibilities