Cleaned code after codereview by minsler