Replaced dirty hack with clean solution