Cleaned up code using *session* dynamic var