This duplicates some code in serverside. Maybe we can reuse?