Refactored rps code after watching solution