Fixed issues from the previoius implementation