Move logic to backend

Signed-off-by: Jack Yen <jack@jackyen.com>