Moved amount calculation to separate function