Don't like this part. Maybe there are more elegant ways of doing that?