Fixed minor bug and added more logic